import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from "typeorm";
import { User } from "./user.entity";
import { BaseEntity } from "src/baseEntity";
import { Dept } from "src/dept/dept.entity";
import { RoleEnum } from "src/role/role.enum";
import { System } from "src/system/system.entity";
import { join } from "path";
import { resource } from "src/util/path";


@Entity("user_sys")
export class UserSys extends BaseEntity {

    @ManyToOne(() => System, type => type.persons)
    system: System

    @Column()
    name: string

    @Column({
        nullable: true,
        unique: true
    })
    dingtalk: string

    @ManyToOne(() => Dept)
    dept: Dept

    @OneToOne(() => User, type => type.sys)
    @JoinColumn()
    user: User

    @Column({
        type: "enum",
        enum: RoleEnum,
        default: RoleEnum.member
    })
    role: RoleEnum

    @Column({ nullable: true })
    login_ip: string

    @Column()
    password: string

    @Column({ unique: true })
    account: string

    public static getAvatarPath(id: string | number) {
        return join(resource, "avatar", `${id}.jpg`)
    }
}